/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaz.FrameEncuestas;

import conex.EnqLibConx;
import estructuras.*;
import interfaz.PanelMiembro;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import javax.swing.*;
import javax.swing.JOptionPane;
import javax.swing.WindowConstants;

/**
 *
 * @author Shadow
 */
public class FrameAskFree extends javax.swing.JFrame implements ActionListener{

    private int foo;
    private String strTemp[]=new String[4];
    
    private Survey s;
    private RespEnq re;
    private StructQuest struc;
    ArrayList <String> datoEnc;
    
    //<editor-fold defaultstate="collapsed" desc="Variables Menu">
    JMenuBar menuBar;
    JMenu menu;
    JMenuItem menuItem;
    JRadioButtonMenuItem rbMILang[];
    
    //</editor-fold>
    
    public FrameAskFree(int foo,Survey s,RespEnq re,ArrayList <String> datos,StructQuest forma) {
        this.foo=foo;
        this.s=s;
        this.re=re;
        this.datoEnc=datos;
        struc=forma;
        
        setTitle(s.getName());
        
        initComponents();
        menuCharger();
        setIdioma(foo);
        
        setDefaultCloseOperation (WindowConstants.EXIT_ON_CLOSE);
        setLocation(10,20);
        setSize(420, 400);
        setVisible (true);
    }
    
    public void setIdioma(int foo){
        this.foo=foo;
        strTemp[0]="Pregunta"+s.getActual();strTemp[1]="Question"+s.getActual();strTemp[2]="Frage"+s.getActSize();strTemp[3]="Question"+s.getActSize();
        jlNumAsk.setText(strTemp[foo]);
        jlAsk.setText(struc.getQuest(foo));
        strTemp[0]="Siguiente";strTemp[1]="Next";strTemp[2]="Nächste";strTemp[3]="Prochain";
        jbNext.setText(strTemp[foo]);
        //idioma en el menu
        strTemp[0]="Idioma";strTemp[1]="Language";strTemp[2]="Sprache";strTemp[3]="langue";
        menu.setText(strTemp[foo]);
        strTemp[0]="Selecciona tu idioma";strTemp[1]="Select your language";strTemp[2]="Wählen Sie Ihre Sprache";strTemp[3]="Choisissez votre langue";
        menuItem.setText(strTemp[foo]);

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jlNumAsk = new javax.swing.JLabel();
        jlAsk = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtaComent = new javax.swing.JTextArea();
        jbNext = new javax.swing.JButton();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jlNumAsk.setText("jLabel2");
        getContentPane().add(jlNumAsk, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));

        jlAsk.setText("jLabel2");
        getContentPane().add(jlAsk, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 30, -1, -1));

        jtaComent.setColumns(20);
        jtaComent.setRows(5);
        jScrollPane2.setViewportView(jtaComent);

        getContentPane().add(jScrollPane2, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 50, 380, 230));

        jbNext.setText("");
        jbNext.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbNextActionPerformed(evt);
            }
        });
        getContentPane().add(jbNext, new org.netbeans.lib.awtextra.AbsoluteConstraints(150, 300, -1, -1));

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jbNextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbNextActionPerformed
        if(jtaComent.getText().compareToIgnoreCase("")!=0){
            re.setCom(jtaComent.getText());
            if(!s.islast()){
                switch(s.getNext()){
                    case 0:new FrameAskFree(foo,s,re,datoEnc,s.getNextStq());break;
                    case 1:new FrameLikeIt(foo,s,re,datoEnc,s.getNextLI());break;
                    case 2:new FrameImaQ(foo,s,re,datoEnc,s.getNextStIQ());break;
                    case 3:new FrameMouseTraking(foo,s,re,datoEnc,s.getNextQG());
                    default:break;
                }
            }else{
                EnqLibConx eLC=new EnqLibConx();
                eLC.setRes(re, datoEnc, s.getName());
                strTemp[0]="Gracias por Participar";strTemp[1]="Write your Answer";
                strTemp[2]="Schreiben Sie Ihre Antwort";strTemp[3]="Ecrivez votre réponse";
                JOptionPane.showMessageDialog(null,strTemp[foo]);
                new PanelMiembro(foo);
            }
            this.dispose();
        }else{
            strTemp[0]="Ecriba su respuesta";strTemp[1]="Write your Answer";
            strTemp[2]="Schreiben Sie Ihre Antwort";strTemp[3]="Ecrivez votre réponse";
            JOptionPane.showMessageDialog(null,strTemp[foo]);
        }
    }//GEN-LAST:event_jbNextActionPerformed
    
    public void menuCharger(){
    menuBar=new JMenuBar();
    menu = new JMenu();
    strTemp[0]="Idioma";strTemp[1]="Language";strTemp[2]="Sprache";strTemp[3]="langue";
    menu.setText(strTemp[foo]);
    menuBar.add(Box.createHorizontalGlue());
    menuBar.add(menu);
    strTemp[0]="Selecciona tu idioma";strTemp[1]="Select your language";strTemp[2]="Wählen Sie Ihre Sprache";strTemp[3]="Choisissez votre langue";
    menuItem = new JMenuItem(strTemp[foo]);
    menuItem.setEnabled(false);
    menu.add(menuItem);
    menu.addSeparator();
    rbMILang= new JRadioButtonMenuItem[4];
    rbMILang[0]= new JRadioButtonMenuItem("Español");
    rbMILang[1]= new JRadioButtonMenuItem("English");
    rbMILang[2]= new JRadioButtonMenuItem("Deutsh");
    rbMILang[3]= new JRadioButtonMenuItem("Française");
    rbMILang[foo].setSelected(true);
    menu.addSeparator();
    for(int i=0;i<4;i++){
        menu.add(rbMILang[i]);
        rbMILang[i].addActionListener(this);
    }
    this.setJMenuBar(menuBar);
        //this.add(menuBar);
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JButton jbNext;
    private javax.swing.JLabel jlAsk;
    private javax.swing.JLabel jlNumAsk;
    private javax.swing.JTextArea jtaComent;
    // End of variables declaration//GEN-END:variables

    @Override
    public void actionPerformed(ActionEvent e) {
        for(int i=0;i<4;i++){
            if(e.getSource()==rbMILang[i]){
                for(int j=0;j<4;j++){
                    rbMILang[j].setSelected(false);
                }
                rbMILang[i].setSelected(true);
                setIdioma(i);
            }
        }
    }
}
